package com.example.bms.controller;
import com.example.bms.entity.ApiResult;
import com.example.bms.entity.FillQuestion;
import com.example.bms.serviceimpl.FillQuestionServiceImpl;
import com.example.bms.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @apiNote 实现对填空题的增加和查询
 * @author 钟顺浩
 * @email 2918185121@qq.com
 * @since 1.0.0
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST,RequestMethod.PUT,RequestMethod.DELETE})
public class FillQuestionController {

    @Autowired
    private FillQuestionServiceImpl fillQuestionService;


    /**
     * @apiNote 增加题库填空题试题
     * @param fillQuestion 填空题题库的实体类
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @PostMapping("/fillQuestion")
    public ApiResult add(@RequestBody FillQuestion fillQuestion) {
        int res = fillQuestionService.add(fillQuestion);
        if (res != 0) {
            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }


    /**
     * @apiNote 查询最后一条questionId
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @GetMapping("/fillQuestionId")
    public ApiResult findOnlyQuestionId() {
        FillQuestion res = fillQuestionService.findOnlyQuestionId();
        return ApiResultHandler.buildApiResult(200,"查询成功",res);
}
}
